export default {
    namespace: "counter",
    state: 10,
    reducers: {
        increase: state => state + 1,
        decrease: state => state - 1,
        add: (state, { payload }) => state + payload,
    },
    effects: {
        *asyncAdd({ payload }, { put }) {
            // throw new Error('xxx') // 测试onError
            yield new Promise((resove) => setTimeout(resove, 2000))
            yield put({ type: 'add', payload })
        }
    },
    subscriptions: { // 这些函数会在模型加入到仓库中后立即运行
        resizeIncrease: ({ dispatch, history }) => {
            // 订阅窗口尺寸变化
            window.onresize = () => dispatch({ type: 'increase' })
        },
        m2: () => console.log('m2 exec')
    }
}